package com.zjsru.oneDay202204;

/**
 * @Author: likew
 * @Date: 2022/4/7
 * 旋转字符串
 * 例如, 若 s = 'abcde'，在旋转一次之后结果就是'bcdea' 。
 *
 * 输入: s = "abcde", goal = "cdeab"
 * 输出: true
 * 输入: s = "abcde", goal = "abced"
 * 输出: false
 */
public class rotateString {
    public boolean rotateString(String s, String goal) {
        if(s.length() != goal.length()){
            return false;
        }
        int len = s.length();
        for (int i = 0; i < len; i++) {
            if(contains(s,goal,i)){
                return true;
            }
        }
        return false;
    }
    
    private boolean contains(String s, String goal, int offset) {
        int len = s.length();
        for (int j = 0; j < len; j++) {
            if(s.charAt(j) != goal.charAt((j + offset) % len)){
                return false;
            }
        }
        return true;
    }
    
    public static void main(String[] args) {
        rotateString rotateString = new rotateString();
        String s = "abbbe";
        String goal = "bbeab";
        System.out.println(rotateString.rotateString(s, goal));
    }
}
